package com.ldc.common.model;

public class BaseModel<T> {
    private static final int SUCCESS_CODE = 0;
    private final static int NOT_LOGIN_CODE = -1001;//登录失败
    T data;
    int errorCode;
    String errorMsg;


    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public boolean isSuccess() {
        return errorCode == SUCCESS_CODE;
    }

    public boolean notLogin() {
        return errorCode == NOT_LOGIN_CODE;
    }

    public boolean isFailed() {
        return !isSuccess();
    }


    public static BaseModel<Object> fail() {
        BaseModel<Object> model = new BaseModel<>();
        model.setErrorCode(1);
        model.setData(null);
        model.setErrorMsg("Unknown error");
        return model;
    }
}
